package com.yy.micro.magic.data.entity;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.yy.micro.magic.data.model.base.JpaObjectWithDynamicFields;
import com.yy.micro.magic.data.model.converter.TypedListConverter;
import com.yy.micro.magic.data.model.converter.TypedMapConverter;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Proxy;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;
@Proxy(lazy = false)
@Entity
@Table(name = "M_MAGIC_RULE")
public class MagicRuleEntity extends JpaObjectWithDynamicFields {
    @Id
    @Column(name="RULE_ID")
    @GeneratedValue(strategy = GenerationType.AUTO,generator = "snowflake")
    @GenericGenerator(name = "snowflake",strategy = SnowflakeIdWorker.NAME)
    @JsonSerialize(using = ToStringSerializer.class)
    private long ruleId;
    @NotNull
    @Column(name = "[KEY]",nullable = false)
    private String key;
    @Column(name = "[NAME]")
    private String name;
    private String alias;
    @Column(name = "[VALUE]")
    private String value;
    private String description;
    private String input;
    private String output;
    private String formula;
    @Column(nullable = false)
    @NotNull
    private String strategy;
    @Convert(converter = TypedListConverter.class)
    private List<String> params;
    private String format;
    @Column(name = "FROM_FORMAT")
    private String fromFormat;
    private int scala=-1;
    @Column(name = "SYNC_PARENT")
    private boolean syncParent = Boolean.FALSE;
    private boolean dynamic = Boolean.FALSE;

    @Convert(converter = TypedMapConverter.class)
    private Map<String,Object> properties;

    private boolean disable = Boolean.FALSE;

    public long getRuleId() {
        return ruleId;
    }

    public void setRuleId(final long ruleId) {
        this.ruleId = ruleId;
    }

    public String getKey() {
        return key;
    }

    public void setKey(final String key) {
        this.key = key;
    }

    public String getName() {
        return name;
    }

    public void setName(final String name) {
        this.name = name;
    }

    public String getAlias() {
        return alias;
    }

    public void setAlias(final String alias) {
        this.alias = alias;
    }

    public String getValue() {
        return value;
    }

    public void setValue(final String value) {
        this.value = value;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(final String description) {
        this.description = description;
    }

    public String getInput() {
        return input;
    }

    public void setInput(final String input) {
        this.input = input;
    }

    public String getOutput() {
        return output;
    }

    public void setOutput(final String output) {
        this.output = output;
    }

    public String getFormula() {
        return formula;
    }

    public void setFormula(final String formula) {
        this.formula = formula;
    }

    public String getStrategy() {
        return strategy;
    }

    public void setStrategy(final String strategy) {
        this.strategy = strategy;
    }

    public List<String> getParams() {
        return params;
    }

    public void setParams(final List<String> params) {
        this.params = params;
    }

    public String getFormat() {
        return format;
    }

    public void setFormat(final String format) {
        this.format = format;
    }

    public String getFromFormat() {
        return fromFormat;
    }

    public void setFromFormat(final String fromFormat) {
        this.fromFormat = fromFormat;
    }

    public int getScala() {
        return scala;
    }

    public void setScala(final int scala) {
        this.scala = scala;
    }

    public boolean isSyncParent() {
        return syncParent;
    }

    public void setSyncParent(final boolean syncParent) {
        this.syncParent = syncParent;
    }

    public boolean isDynamic() {
        return dynamic;
    }

    public void setDynamic(final boolean dynamic) {
        this.dynamic = dynamic;
    }

    public Map<String, Object> getProperties() {
        return properties;
    }

    public void setProperties(final Map<String, Object> properties) {
        this.properties = properties;
    }

    public void setDisable(final boolean disable) {
        this.disable = disable;
    }

    public boolean isDisable() {
        return disable;
    }

    @Override
    public String getIdProperty() {
        return "ruleId";
    }
}
